package cn.zou.core.json;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

/**
 * 响应设置
 * @author zoujin
 *
 */
public class ResponseUtils {
	private static void render(HttpServletResponse response,String contType,String text){
		response.setContentType(contType);
		try {
			response.getWriter().write(text);
			response.getWriter().close();
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
	}
	/**
	 * 响应json数据
	 * @param response
	 * @param text
	 */
	public static void renderJson(HttpServletResponse response,String text){
		render(response, "appliction/json;charset=utf-8", text);
	}
	/**
	 * 响应xml数据
	 * @param response
	 * @param text
	 */
	public static void renderXml(HttpServletResponse response,String text){
		render(response, "text/xml;charset=UTF-8", text);
	}
	public static void renderText(HttpServletResponse response,String text){
		render(response, "text/plain;charset=UTF-8", text);
	}
}
